2 // SafariWebExtensionHandler.swift
5 // Created by Ruben Beltran del Rio on 9/13/23.
11 class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
13 func beginRequest(with context: NSExtensionContext) {
14 let request = context.inputItems.first as? NSExtensionItem
17 if #available(iOS 17.0, macOS 14.0, *) {
18 profile = request?.userInfo?[SFExtensionProfileKey] as? UUID
20 profile = request?.userInfo?["profile"] as? UUID
24 if #available(iOS 17.0, macOS 14.0, *) {
25 message = request?.userInfo?[SFExtensionMessageKey]
27 message = request?.userInfo?["message"]
30 os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@ (profile: %@)", String(describing: message), profile?.uuidString ?? "none")
32 let response = NSExtensionItem()
33 response.userInfo = [ SFExtensionMessageKey: [ "echo": message ] ]
35 context.completeRequest(returningItems: [ response ], completionHandler: nil)